Skip to content

ENH: add adaptive_max_weight option - #604

Merged
redeboer merged 9 commits into
mainfrom
faster-hit-and-miss
Nov 17, 2026
Merged

redeboer merged 9 commits into
mainfrom
faster-hit-and-miss

Conversation

@redeboer

@redeboer redeboer commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

⚙️ Enhancements

  • TFPhaseSpaceGenerator gets a keyword-only adaptive_max_weight argument. With adaptive_max_weight=True, the hit-and-miss step draws its random numbers up to an estimate of the maximum weight instead of up to the upper bound that phasespace guarantees. The estimate is the largest weight of the bunches so far with a margin of 5%. When a bunch exceeds it, the estimate is raised and generation restarts, like in IntensityDistributionGenerator. The estimate never exceeds the bound, so the option is never less efficient than the default.

  • The default stays False, so existing code gets exactly the same samples for the same seed. With the option, the distribution is the same, but the events differ.

  • The gain grows with the number of final state particles. For 10,000 events of a 5 GeV particle that decays into pions, a local run took:

    Pions Default adaptive_max_weight=True
    3 0.30 s 0.31 s
    5 1.36 s 0.58 s
    6 8.60 s 0.77 s
    7 113 s 0.96 s

    For few particles, both settings need a single bunch of 50,000 events, so the times are equal.

📝 Documentation

  • A new phase space page (preview) under the amplitude analysis examples explains why the default hit-and-miss step accepts few events for many final state particles and shows how to use adaptive_max_weight=True. Benchmarks and statistical comparisons of both settings live in TR-038, so that the page only illustrates the feature and runs in about 10 s. Until TR-038 is published, nitpick_ignore suppresses the unresolved link to it.

Squash commit messages

* DOC: add phase space page with link to TR-038

@redeboer redeboer added this to the 0.4.18 milestone Nov 9, 2026
@redeboer redeboer added the ⚙️ Enhancement Improvements and optimizations of existing features label Nov 9, 2026
@redeboer redeboer changed the title ENH: add adaptive_max_weight option ENH: add adaptive_max_weight option Nov 9, 2026
@redeboer redeboer self-assigned this Nov 9, 2026

@redeboer redeboer left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'TensorWaves benchmark results'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 5b07657 Previous: 96c79ad Ratio
benchmarks/expression.py::test_fit[1000-ScipyMinimizer-numpy] 7.2276343184668725 iter/sec (stddev: 0.00028008404111654756) 16.20089733282377 iter/sec (stddev: 0.0002919331648110754) 2.24
benchmarks/expression.py::test_fit[1000-ScipyMinimizer-numba] 7.21115272770527 iter/sec (stddev: 0.0004044606208413481) 15.719486023422135 iter/sec (stddev: 0.00020436080552564467) 2.18
benchmarks/expression.py::test_fit[1000-ScipyMinimizer-tf] 0.6188479173610196 iter/sec (stddev: 0.00418789445532882) 1.4510339953328852 iter/sec (stddev: 0.002136985793101471) 2.34
benchmarks/unbinned_nll.py::test_unbinned_nll_normalization_formula[original-numpy] 28.41610169418186 iter/sec (stddev: 0.0007061197959512932) 83.16394792483862 iter/sec (stddev: 0.00007097826620654797) 2.93
benchmarks/unbinned_nll.py::test_unbinned_nll_normalization_formula[original-tensorflow] 60.108170797735816 iter/sec (stddev: 0.00041351329718404377) 127.70369911146068 iter/sec (stddev: 0.00019483109407062498) 2.12
benchmarks/unbinned_nll.py::test_unbinned_nll_normalization_formula[optimized-numpy] 37.03909610031483 iter/sec (stddev: 0.0005525523557448707) 128.90182339052615 iter/sec (stddev: 0.00007047725297610706) 3.48
benchmarks/unbinned_nll.py::test_unbinned_nll_normalization_formula[optimized-tensorflow] 61.67090841262568 iter/sec (stddev: 0.001321918594487155) 157.36058719247046 iter/sec (stddev: 0.0002361793019890102) 2.55
benchmarks/unbinned_nll.py::test_unbinned_nll_estimator[numpy] 126.83837785976952 iter/sec (stddev: 0.00016396145310168205) 342.6441228883796 iter/sec (stddev: 0.0001794193509548101) 2.70
benchmarks/unbinned_nll.py::test_unbinned_nll_estimator[numba] 96.73901726107701 iter/sec (stddev: 0.0010175312768236438) 535.093309487275 iter/sec (stddev: 0.00012515060065815384) 5.53

This comment was automatically generated by workflow using github-action-benchmark.

@redeboer redeboer added the 📝 Docs Improvements or additions to documentation label Nov 9, 2026
@redeboer
redeboer force-pushed the faster-hit-and-miss branch from 5b07657 to 800ae3f Compare November 9, 2026 09:45
@redeboer
redeboer marked this pull request as ready for review November 12, 2026 16:42
@redeboer
redeboer merged commit d87354f into main Nov 17, 2026
24 checks passed
@redeboer
redeboer deleted the faster-hit-and-miss branch November 17, 2026 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📝 Docs Improvements or additions to documentation ⚙️ Enhancement Improvements and optimizations of existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Speed up hit-and-miss sampling of phase space generators

2 participants